﻿/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : join_03.js                                 
*  Description  : 회원가입완료 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-06-21  김효순    Created.
*  2012-06-21  김효순    Complete.
*******************************************************************************/

jQuery(function($){
	function clsDisplay()
	{
		this.infoData = null;
		
		this._init();
	}
	
	clsDisplay.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody");
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, setInfo: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, setAreaText: function(val){
			this._HTMLDom["$layer"].find("tr:eq(7) td").html(_util.nvl(val));
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("tr:eq(0) td").html(this.infoData["이름"]);
			$layer.find("tr:eq(1) td").html(this.infoData["아이디"]);
			$layer.find("tr:eq(2) td").html(this.infoData["닉네임"]);
			$layer.find("tr:eq(3) td").html(this.infoData["이메일"]);
			$layer.find("tr:eq(4) td").html(this.infoData["휴대폰"]);
			$layer.find("p.profile_photo img[alt='프로필 이미지']").width(103).height(123).attr("src", _gf.filePath2Url(this.infoData["이미지"])).error(function(){
				$(this).attr("src", _gf.getDefaultProfileImage());
			});
			$layer.find("tr:eq(7) td").html(document.objUtil.nvl(this.infoData["지역"]));
			$layer.find("tr:eq(8) td").html(document.objUtil.nvl(this.infoData["연령대"]));
			$layer.find("tr:eq(9) td").html(document.objUtil.nvl(this.infoData["직업"]));
			$layer.find("tr:eq(10) td").html(document.objUtil.nvl(this.infoData["핸디"], 0));
			$layer.find("tr:eq(11) td").html(document.objUtil.nvl(this.infoData["평균타수"], 0));
		}
	}
	
	// 서버통신
	function clsComm()
	{

		//초기화
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			
		}
	}
	
	// 초기화면 제어
	function clsControl()
	{
		//초기화
		this.objComm = null;
		this.objDisplay = null;
		
		this._permitStart = null;
	}
	
	clsControl.prototype = {
		//초기화
		_init: function(){
			this._preload();
			
			this.objComm = new clsComm();
			this.objDisplay = new clsDisplay();

			this._beforeStart();
			this._bind();
		}
		, _preload: function(){
			_gf.spinStart();
		}
		, _beforeStart: function(){
			var thisClass = this;
			this._permitStart = {
				
			}
			
			document.objUtil.executeThread(function(){
				var myInfo = _gf.getMyInfoData();
				var areaCodeList = _gf.getAreaCodeData();
				var ageCodeList = _gf.getAgeCodeData();
				
				for(var k in thisClass._permitStart){
					if(!thisClass._permitStart[k]) return false;
				}
				
				return (myInfo && myInfo["아이디"] && areaCodeList && ageCodeList);
			}, function(){
				_gf.spinEnd();
				thisClass._start();
			});
			
			
		}
		, _bind: function(){
			var thisClass = this;
			
			$(document).on("click", "img[alt='골프인 홈'], img[alt='마이골프인']", function(){
				var bName = $(this).attr("alt");

				switch(bName){
					case "골프인 홈": 
						thisClass.goHomePage();
						break;
					case "마이골프인": 
						thisClass.goMyPage();
						break;
				}
			});
		}
		, _start: function(){
			var myInfo = _gf.getMyInfoData();
			var areaCodeList = _gf.getAreaCodeData();
			var ageCodeList = _gf.getAgeCodeData();
			
			this.objDisplay.setInfo(myInfo);
			
			var key = myInfo["지역코드"];
			var t = _gf.getAreaText(key, true);
			this.objDisplay.setAreaText(t);
		}
		// 골프인 홈 이동
		, goHomePage: function(){
			var szLink = _ROOT + "/index";
			document.location.href = szLink;
		}
		// 마이페이지
		, goMyPage: function(){
			var szLink = _ROOT + "/mypage/my_home.html";
			var a = document.createElement("A");
			$(a).attr({
				"href": szLink
				, "id": "idPermissionLink"
			}).appendTo($("body")).get(0).click();
			$(a).remove();
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});